<?php
class omekpi_ctl_admin_employee extends desktop_controller{
    var $name = "人员添加";
    var $workground = "performance";

    function index(){
        $params = array(
            'actions' => array(
                array(
                    'label' => '添加员工',
                    'href' => 'index.php?app=omekpi&ctl=admin_employee&act=addEmployee',
                    //'target' => "_blank",
                ),
            ),
            'title'=>'操作员列表',
            'use_buildin_new_dialog' => false,
            'use_buildin_set_tag'=>false,
            'use_buildin_recycle'=>true,
            'use_buildin_export'=>false,
            'use_buildin_import'=>false,
            'use_buildin_filter'=>true,
        );
        $this->finder('omekpi_mdl_employee',$params);
    }
    
    function addEmployee(){
        $this->page('admin/performance/addemployee.html');
    }
    
    function add(){
        $base_filter=array('status'=>1);
        $params = array(
                'title'=>'操作员列表',
                'use_buildin_new_dialog' => false,
                'use_buildin_set_tag'=>false,
                'use_buildin_recycle'=>false,
                'use_buildin_export'=>false,
                'use_buildin_import'=>false,
                'use_buildin_filter'=>true,
                'base_filter' => $base_filter,
            );
        $this->finder('desktop_mdl_users',$params);
    }
    
    function getUserId(){
        $account = app::get('pam')->model('account');
        $user_id = $_POST['user_id'];
        $filter['account_id'] = $user_id;
        
        $data = $account->getList('account_id,login_name',$filter,0,-1);
        $user=app::get('desktop')->model('users');
        $user_filter['user_id'] = $user_id;
        $op_no = $user->getList('user_id,op_no,name',$user_filter,0,-1);

        if (!empty($data)){
            foreach ($data as $k => $item){
                foreach($op_no as $ke=>$va){
                    if($item['account_id']==$va['user_id']){
                        $item['op_no']=$va['op_no']?$va['op_no']:'-';
                        $item['name'] = $va['name'];
                    }
                }
                $rows[] = $item;
            }
        }
        echo json_encode($rows);
    }    
    
    function doadd(){//新的人员产生以后 不再产生初始化记录
        $this->begin('index.php?app=omekpi&ctl=admin_employee&act=index');
        $users = $_POST;
        $employee= &$this->app->model('employee');
        $uid = $users['ut'];
        $ulogin_name = $users['at'];
        $op_no = $users['ot'];
        $uname = $users['nr'];
        $type = $users['select'];
        $i=0;
        for($i=0;$i<(count($ulogin_name));$i++){
            $res = $employee->dump(array('employee_account_id'=>$uid[$i],'employee_type'=>$type));
            if($res){
                $this->end(false,'保存失败'.$ulogin_name[$i].'已存在');
            }
        }
        
        for($i=0;$i<(count($ulogin_name));$i++){
            $tmp['employee_account_id'] = $uid[$i];
            $tmp['employee_name'] = $uname[$i];
            $tmp['employee_login_name'] = $ulogin_name[$i];
            $tmp['employee_op_no']=$op_no[$i];
            $tmp['employee_type'] = $type;
            $employee->insert($tmp);
            $tmp = null;
        }
        $this->end(true,'保存成功');
    }
    
}
?>
